<?php
/**
 * Date: 15-1-22
 * Time: 上午10:49
 * @package  ajax
 * @subpackage  dunch
 * @author   allen.qiang <allen.qiang@fistforward.com>
 */

quanli_require('module/base/customer/quanliCust.class.php');//载入会员类
quanli_require('module/base/dunch/dunch.class.php');//载入下午茶操作类
class ajax_dunch {

    public function execute() {

        if (isset($_REQUEST['operFlg']) && is_numeric($_REQUEST['operFlg']) && $_REQUEST['operFlg'] > 0) {

            switch ($_REQUEST['operFlg']) {

                case 1://验证会员信息
                    $this->checkCustMaster();
                    break;
                case 2://发送短信验证码
                    $this->send_sms();
                    break;
                case 3://立即体验
                    $this->checkCode();
                    break;
                case 4://套餐详情
                    $this->selInfo();
                    break;
                case 5://获取商品信息、数量加入session
                    $this->goodsSession();
                    break;
                case 6://提交订单
                    $this->createBill();
                    break;
                case 7://吐槽
                    $this->tucao();
                    break;
                case 8://开抢
                    $this->panic();
                    break;
                case 9://add by allen.qiang 《allen.qiang@fistforward.com》MK-FUN-AC-004 下午茶项目迭代--下午茶会员权益
                    $this->ckeckRight();
                    break;
                case 10://add by allen.qiang 《allen.qiang@fistforward.com》MK-FUN-AC-0041 登录或注册会员信息
                    $this->quickLogin();
                    break;




                case 100://访问限制
                    $this->sayNo();
                    break;
                case 101://验证登陆状态
                    $this->checkLogin();
                    break;

                default:
                    $this->toReturn('参数错误');
                    break;

            }

        } else {
            $this->toReturn('参数错误');
        }


    }

    /**
     * 返回信息
     * @param string $message
     * @param int $code
     * @param mixed $data
     */
    private function toReturn( $message, $code = 400, $data = '' ) {

        die( json_encode( array( 'code' => $code, 'message' => $message, 'data' => $data ) ) );

    }

    /*
     * 访问限制
     */
    public function sayNo(){
        global $G_SHOP;
        $url=$_REQUEST['url'];
        $arr = explode("#",$url);
      if(!empty($arr[1]) && $arr[1]!='home' &&$arr[1]!='Fill_in' ){
          if(!$G_SHOP->currentCustomerID){
              $G_SHOP->currentCustomerID =$_COOKIE['dunchCookie_custID'];
          }
          if(!$G_SHOP->currentPCustID){
              $G_SHOP->currentPCustID =$_COOKIE['dunchCookie_pcustID'];
          }
              $custID=$G_SHOP->currentCustomerID;

              if(!empty($custID)){
                  $checkSql="select custID,pcustID from dunch_cust_master where custID=?  and  brandID=1";
                  $quest=$G_SHOP->DBCA->stmt_query($checkSql,'s',$custID);
                  if(!empty($quest)){

                      foreach($quest as $quest1){
                          $questArray=array(
                              'custID'=>$quest1->custID,
                              'pcustID'=>$quest1->pcustID
                          );
                      }
                  }

                  if(empty($questArray['pcustID'])){
                      returnJsonData("非特定会员",200);
                  }else{


                      //查询用户地址信息
                      //载入会员收货地址类
                      quanli_require('module/base/customer/custDeliver.class.php');
                      //实例化收货地址类
                      $custDeliver = new custDeliver();
                      //查询参数
                    $deliverSql="select deliverID from dunch_address where pcustID=?";
                    $deliverQuest=$G_SHOP->DBCA->stmt_query($deliverSql,'s',$G_SHOP->currentPCustID);
                      foreach($deliverQuest as $deliverQuery){
                          $arg_array = array(
                              'pcustID' => $G_SHOP->currentPCustID,
                              'deliverID'=>$deliverQuery->deliverID
                          );
                          //查询会员收货地址信息
                          $custDeliver_array[] = $custDeliver->searchCustDeliver( $arg_array );
                      }

    //                  $arg_array = array(
    //                      'pcustID' => $G_SHOP->currentPCustID,
    //                      'deliverID'=>1
    //                  );
    //                  //查询会员收货地址信息
    //                  $custDeliver_array = $custDeliver->searchCustDeliver( $arg_array );

                      $addressHtml="";
                      if(!empty($custDeliver_array)){


                      foreach($custDeliver_array as  $custDeliver){
                          if(!empty($custDeliver)){
                          foreach($custDeliver as  $custDeliver2){

                          $addressHtml.="<li id=".$custDeliver2['deliverID']." onclick='zt(this)'>".$custDeliver2['address']."</li>";
                          }
                          }
                      }

                      }
                      returnJsonData($addressHtml,400);
                  }
              }else{
                      returnJsonData("未验证禁止访问",200);
                  }
          }else if(empty($arr[1]) || $arr[1]=='home' ){
          if(!$G_SHOP->currentPCustID){
              $G_SHOP->currentPCustID =$_COOKIE['dunchCookie_pcustID'];
          }

          if($G_SHOP->currentPCustID){
                $checkSql="select custID,pcustID from dunch_cust_master where pcustID=?  and  brandID=1";
                $quest=$G_SHOP->DBCA->stmt_query($checkSql,'s',$G_SHOP->currentPCustID);
                if(!empty($quest)){

                    foreach($quest as $quest1){
                        $questArray=array(
                            'custID'=>$quest1->custID,
                            'pcustID'=>$quest1->pcustID
                        );
                    }
                }

                if(empty($questArray['pcustID'])){
                    returnJsonData("非特定会员",200);
                }else{
                returnJsonData("已登录",300);
                }
            }
      }


      }
    /*
     * 加减按钮
     * 验证会员信息
     */
    public function checkLogin(){
        global $G_SHOP;
        $cookieCustID=$_COOKIE['dunchCookie_custID'];
        $custID=$G_SHOP->currentCustomerID;
        if( !empty($cookieCustID)  ||  !empty($custID)){
            returnJsonData('YES',200);
        }else{
            returnJsonData('NO',400);
        }
    }

    /**
     * 验证会员信息
     */
    public  function checkCustMaster(){

        global $G_SHOP;
        $phone=$_REQUEST['phone'];
        $checkSql="select custID,pcustID from dunch_cust_master where custID=?  and  brandID=1";
        $quest=$G_SHOP->DBCA->stmt_query($checkSql,'s',$phone);
        if(!empty($quest)){

        foreach($quest as $quest1){
            $questArray=array(
                'custID'=>$quest1->custID,
                'pcustID'=>$quest1->pcustID
            );
        }

        }
        if($questArray['pcustID']){

            returnJsonData('ok',200,$questArray);
        }else{
            returnJsonData('ok',400);
        }

       // returnJsonData('ok',200,$first_level_array);

    }
    /*
     * 发送短信验证码
     */
    public function send_sms(){
        global $G_SHOP;
        $phone=$_REQUEST['phone'];//手机号码
        //加载短信类
        quanli_include('module/base/common/quanliSms.class.php');

        //实例化短信类
        $quanliSms = new quanliSms();


        if (!isset($phone) || !is_mobile($phone)) {
            returnJsonData('参数错误');
        }


        $current_time = time(); //当前时间戳
        $last_send_time = $G_SHOP->sessionCache_get('sms_yzm_time_' . $phone); //上一次发放短信的时间戳
        if (!empty($last_send_time) && $current_time - $last_send_time < 30) {
            returnJsonData('手机短信已发送，请30s以后再试');
        }

        /**
         * ============================
         * 发送短信
         * ============================
         */

        //生成短信验证码
        $sms_yzm = $quanliSms->createSmsCode();

        //生成短信内容
        $data_array = array(
            '$sms_yzm' => $sms_yzm,
            '$mobile' => $phone
        );
        $sms_content = $quanliSms->getSmsContent( 'dunch_mobile', $data_array );
        if (!$sms_content) {
            returnJsonData('短信初始化失败', 404);
        }

        //发送短信
        $result_array = $quanliSms->sendSMS( $phone, $sms_content );

        /**
         * ============================
         * 发送短信
         * ============================
         */
       // if ($result_array['code'] == 200) { //本地环境 注释掉
            //保存短信验证码到redis
            $G_SHOP->sessionCache_set('sms_yzm_' . $phone, md5($sms_yzm), 3600);//将验证码信息保存到memcache中去
            $G_SHOP->sessionCache_set('sms_yzm_time_' . $phone, time(), 3600);

    //    }
        returnJsonData($result_array,200);
    }
    /*
     * 立即体验
     * 验证手机号and短信验证码是否匹配
     */
    public function checkCode(){


        global $G_SHOP;
        $phone=$_REQUEST['phone'];
        $code=$_REQUEST['code'];

        //测试环境，暂不用
//        //检查短信验证码
//        $sms_ysm = $G_SHOP->sessionCache_get('sms_yzm_' . $phone);
//        if (is_null($sms_ysm)) {
//            returnJsonData('短信验证码已失效', 400);
//        } elseif ($sms_ysm != md5($code)) {
//            returnJsonData('短信验证码有误',400);
//        }
//
//        $G_SHOP->sessionCache_remove( 'sms_yzm_' .$phone );
//        $G_SHOP->sessionCache_remove( 'sms_yzm__time_' . $phone );
        //$zc=$this->quickLogin();
        //实例会员类
        $quanliCust = new quanliCust();

        //查询会员信息
        $arg_array = array(
            'custID' =>$phone
        );
        $customer_array = $quanliCust->searchCustomerDetail( $arg_array );

        setcookie('dunchCookie_custID', $customer_array['custID'], time()+3600*24*7,'/');//手机号存入cookie
        setcookie('dunchCookie_pcustID', $customer_array['pcustID'], time()+3600*24*7,'/');//会员ID存入cookie
        //更新会员登录信息
        $quanliCust->shopCheckin( $customer_array, 0 );
        returnJsonData('短信验证成功',200);


    }
/*
 * 查询详情
 */
    public function selInfo(){
        global $G_SHOP;
        $package_id=$_REQUEST['package_id'];
//        $detalSql="select goodsName,frenchName,chineseBrief from dunch_package_detail join goods_sale on dunch_package_detail.product_code=goods_sale.product_code where package_id=?";
//        $datalQuest=$G_SHOP->DBCA->stmt_query($detalSql,'s',$package_id);
//        foreach($datalQuest as  $datalQuery){
//               $detal[]=array(
//                   'goodsName'=>$datalQuery->goodsName,
//                   'frenchName'=>$datalQuery->frenchName,
//                   'chineseBrief'=>$datalQuery->chineseBrief
//
//               );
//        }

        $packageSql="SELECT package_image_3,package_image,package_remark,package_remark_2 FROM dunch_package where package_id=?";
        $packageQuest=$G_SHOP->DBCA->stmt_query($packageSql,'s',$package_id);

        foreach($packageQuest as  $packageQuery){
            $cake=explode(',',$packageQuery->package_remark);
            $coffee=explode(',',$packageQuery->package_remark_2);
            $detal1=array(
                'package_image_3'=>$packageQuery->package_image_3,
                'package_image'=>$packageQuery->package_image,
                'cakeName'=>$cake[0],
                'coffeeName'=>$coffee[0],
                'package_remark'=>$cake[1],
                'package_remark_2'=>$coffee[1]
            );
        }
        $return=array(
            'package'=>$detal1,
//            'info'=>$detal,
        );
        returnJsonData($return,200);
    }
    /*
     *  查询商品编号 数量
     *  商品信息存入session
     * 查询用户地址信息
     */
    public function goodsSession(){
        global $G_SHOP;
        $package=$_REQUEST['package'];
        foreach($package as $packageArray){
            $saleSql="SELECT package_num FROM dunch_sale where package_id=? and sale_id=?";
            $saleQuest=$G_SHOP->DBCA->stmt_query($saleSql,'ss',$packageArray['package_id'],$packageArray['saleid']);
            if($saleQuest[0]->package_num<1){
                returnJsonData("已售罄",400);
            }
            $detail="select product_code from dunch_package_detail where package_id =?";
            $detailQuest=$G_SHOP->DBCA->stmt_query($detail,'s',$packageArray['package_id']);
            foreach($detailQuest as $detailQuery){

                $info[$packageArray['saleid']][$packageArray['package_id']][]=array(
                    'code'=>$detailQuery->product_code,
                    'num'=>$packageArray['num']
                );
            }
        }
        //把商品信息加入session or cookie start

        $G_SHOP->sessionCache_set("info_text",$info,G_LOGINSESSION_TIMEOUT);
        //把商品信息加入session or cookie end

        returnJsonData("成功",200);
    }

    /*
     * 提交下午茶订单
     */
    public function createBill(){
        global $G_SHOP;
        if(!$G_SHOP->currentCustomerID){
            $G_SHOP->currentCustomerID =$_COOKIE['dunchCookie_custID'];
        }
        if(!$G_SHOP->currentPCustID){
            $G_SHOP->currentPCustID =$_COOKIE['dunchCookie_pcustID'];
        }
        $newNum=0;
        $info=$G_SHOP->sessionCache_get('info_text');
        foreach($info as $goodsCode){
            foreach($goodsCode as $key=>$goodsCode1){
                foreach($goodsCode1 as $goodsCode2){
                    $newNum+=$goodsCode2['num'];

                }
            }
        }



        $packageSql="select bill_totalAmount from bill_master where  billPlatform=3 and pcustID=? and send_date=? and bill_status!=10 and bill_status!=0";
        $custPackage=$G_SHOP->DBCA->stmt_query($packageSql,'ss',$G_SHOP->currentPCustID,$_REQUEST['dateTime']);
        $custNum=0;
        foreach($custPackage as $packageArray){
            $custNum+=$packageArray->bill_totalAmount;
        }
        /*
         * add by allen.qiang 《allen.qiang@fistforward.com》MK-FUN-AC-004 下午茶项目迭代--下午茶会员权益 start
         */
        $is_rightSql="select is_right from dunch_cust_master where pcustID=? ";
        $isVal=$G_SHOP->DBCA->stmt_query($is_rightSql,'s',$G_SHOP->currentPCustID);


        if(($custNum+$newNum)>4 && $isVal[0]->is_right!=1){
            returnJsonData("每个会员每日限定2个套餐",400);
        }
        /*
         * add by allen.qiang 《allen.qiang@fistforward.com》MK-FUN-AC-004 下午茶项目迭代--下午茶会员权益 end
         */
       /*
       * del by allen.qiang 《allen.qiang@fistforward.com》MK-FUN-AC-004 下午茶项目迭代--下午茶会员权益 end
       */
//        if(($custNum+$newNum)>4 ){
//            returnJsonData("每个会员每日限定2个套餐",400);
//        }
          /*
          * del by allen.qiang 《allen.qiang@fistforward.com》MK-FUN-AC-004 下午茶项目迭代--下午茶会员权益 end
          */

        foreach($info as $key=>$goodsCode){
            foreach($goodsCode as $goodsCode1){
                $numSql="select  count(1) as oldNum  from  dunch_sale WHERE sale_id=? and package_num>=".$goodsCode1[0]['num']."";
                $oldNum=$G_SHOP->DBCA->stmt_query($numSql,'s',$key);
                if($oldNum[0]->oldNum<1){
                    returnJsonData("已售罄",400);
                }
            }

        }





        $info=$G_SHOP->sessionCache_get('info_text');
        foreach($info as $key=>$goodsCode){
            $checkSql="SELECT sale_date FROM dunch_sale where  sale_id=?";
            $chcekTime=$G_SHOP->DBCA->stmt_query($checkSql,'s',$key);
            if($chcekTime[0]->sale_date!=$_REQUEST['dateTime']){
                returnJsonData("哎呀,<br/>已超过本日最晚下单时间，<br/>您可以返回选购明天的套餐",400);

            }

        }


        $payId = $_REQUEST['payId'];//支付方式ID
        $contacts = $_REQUEST['contacts'];//联系人
        $mobile = $_REQUEST['mobile'];//联系方式
        $m_address = $_REQUEST['m_address'];//收货地址
        $deliveryTimes = $_REQUEST['deliveryTimes'];//收货日期
        $dateTime = $_REQUEST['dateTime'];//收货时间
        $delivery = explode("-", $deliveryTimes);
        $send_time_start=$delivery[0];//配送开始日期
        $send_time_end=$delivery[1];//配送结束日期
        $date_time=date('Y-m-d H:i:s',time());
//error_log($date_time);
//error_log($_REQUEST['dateTime']." 16:15:01");
        $nowTime=date('H:i:s',time());
        if($date_time>$dateTime." 16:00:01"){
            returnJsonData("哎呀,<br/>已超过本日最晚下单时间，<br/>您可以返回选购明天的套餐",400);

        }

        $bill = array();
        $bill['custID'] = $G_SHOP->currentCustomerID;

        $bill['country'] = 440; //区id
        $bill['deliver_name'] = $contacts; //收货人
        $bill['deliver_address'] =$m_address;//收货人地址
        $bill['deliver_mobile'] = $mobile;//收货人手机

//        $bill['is_the_invoice'] = $_REQUEST['is_the_invoice'];
//        $bill['invoice_title_type'] = $_REQUEST['invoice_title_type'];//1：个人 2：单位
//        $bill['invoice_title'] = $_REQUEST['invoice_title']; //发票抬头

        //$bill['invoice_content'] = ''; //发票内容

        $bill['payTypeID'] = $payId; //支付方式ID
        $bill['payment_method_id'] = 0; //付款方式


        $bill['send_date'] = $dateTime;//收货日期
        $bill['send_start_time'] = $send_time_start;//配送开始时间
        $bill['send_end_time'] = $send_time_end;//配送结束时间

       // $bill['billPromotion'] = $config_array['billPromotion'];//促销渠道



        $dunch=new dunch();
        $zt=$dunch->create_bill($bill);

        if($zt['code']==200){

            foreach($info as $key=>$goodsCode){
                foreach($goodsCode as $goodsCode1){
                    $numSql="UPDATE dunch_sale  SET package_num=package_num-".$goodsCode1[0]['num']." WHERE sale_id=? and package_num>=".$goodsCode1[0]['num']."";
                    $oldNum=$G_SHOP->DBCA->stmt_query($numSql,'s',$key);
                    if($oldNum==0){
                        returnJsonData("已售罄",400);
                    }
                }

            }
            foreach($info as  $k=>$bill_goods){
                foreach($bill_goods as  $key=>$bill_goods_2){
                    $packageSql="select package_name from  dunch_package where  package_id=? ";
                    $pageQuet=$G_SHOP->DBCA->stmt_query($packageSql,'s',$key);
                    $packageName=$pageQuet[0]->package_name;
                    $detailSql="select goods_sale.* from  dunch_package_detail join goods_sale on dunch_package_detail.product_code=goods_sale.product_code  where package_id=?";
                    $detailQuest=$G_SHOP->DBCA->stmt_query($detailSql,'s',$key);
                    $postID='';
                    $goodsName='';
                    //查询采购单状态
                    $applySql="SELECT status FROM  dunch_apply where   apply_date=?";
                    $applyQuest=$G_SHOP->DBCA->stmt_query($applySql,'s',$dateTime);
                    $isS=0;//未入库
                    if($applyQuest[0]->status==3){
                        $isS=1;//已入库
                    }

                        foreach($detailQuest as $detailQuery ){
                            if($isS==0){
                                $updSql="UPDATE dunch_stock  SET total_apply_amount=total_apply_amount-".$bill_goods_2[0]['num']." WHERE product_code=? and stock_date=?";
                                $G_SHOP->DBCA->stmt_query($updSql,'ss',$detailQuery->product_code,$dateTime);
                            }else{
                                $updSql="UPDATE dunch_stock  SET total_apply_amount=total_paid_amount-".$bill_goods_2[0]['num']." WHERE product_code=? and stock_date=?";
                                $G_SHOP->DBCA->stmt_query($updSql,'ss',$detailQuery->product_code,$dateTime);
                            }
                            $logSql="select stock_id from  dunch_stock  where  product_code=?";
                            $logQuest=$G_SHOP->DBCA->stmt_query($logSql,'s',$detailQuery->product_code);

                            $dunch_stock_log=new entity("dunch_stock_log");
                            $dunch_stock_log->stock_id=$logQuest[0]->stock_id;

                            $dunch_stock_log->log_type=3;
                            $dunch_stock_log->amount=$bill_goods_2[0]['num'];
                            $G_SHOP->DBCA->save($dunch_stock_log);
                                $postID.=$detailQuery->postID.",";
                                $goodsName.=$detailQuery->goodsName."+";
                            $stock_id=$logQuest[0]->stock_id;
                        }




                    $postID=rtrim($postID, ',');
                    $goodsName=rtrim($goodsName, '+');

                    $dunch_bill_detail=new entity("dunch_bill_detail");
                    $dunch_bill_detail->bill_no=$zt['bill_no'];
                    $dunch_bill_detail->bill_code=$zt['bill_code'];
                    $dunch_bill_detail->package_id=$key;
                    $dunch_bill_detail->package_name=$packageName;
                    $dunch_bill_detail->goods_id_str=$postID;
                    $dunch_bill_detail->goods_name_str=$goodsName;
                    $dunch_bill_detail->buy_amount=$bill_goods_2[0]['num'];
                    $dunch_bill_detail->stock_id=$logQuest[0]->stock_id;;
                    $G_SHOP->DBCA->save($dunch_bill_detail);
                }
            }

            $billSql="select pcustID,bill_receivable_money,goods_name_str,send_start_time,send_end_time,bill_totalAmount from bill_master where bill_code=?";
            $billQuest=$G_SHOP->DBCA->stmt_query($billSql,'s',$zt['bill_code']);

            $returnArray=array(
                "bill_no"=>$zt['bill_no'],
                "pcustID"=>$billQuest[0]->pcustID,
                "bill_receivable_money"=>$billQuest[0]->bill_receivable_money,
                "goods_name_str"=>$billQuest[0]->goods_name_str,
                "ip"=>get_ip(),
                "bill_code"=>$zt['bill_code'],
                "send_start_time"=>$billQuest[0]->send_start_time,
                "send_end_time"=>$billQuest[0]->send_end_time
            );


            returnJsonData("yes",200,$returnArray);
        }else if($zt['code']==404){
            returnJsonData($zt['message'],404);
        }

    }

    /*
     * 吐槽信息
     */
    public function tucao(){
        global $G_SHOP;
        $custID = $_REQUEST['custID'];//申请手机号
        $custName = $_REQUEST['custName'];//联系人名字
        $custMobile = $_REQUEST['custMobile'];//联系方式
        $areaID = $_REQUEST['areaID'];//区ID
        $areaText = $_REQUEST['areaText'];//区名称
        $content = $_REQUEST['content'];//详细地址

        $dunch_tucao=new entity("dunch_tucao");
        $dunch_tucao->custID=$custID;
        $dunch_tucao->custName=$custName;
        $dunch_tucao->mobile=$custMobile;
        $dunch_tucao->areaID=$areaID;
        $dunch_tucao->content=$areaText.$content;
        $dunch_tucao->platform=1;
        $G_SHOP->DBCA->save($dunch_tucao);
        returnJsonData("成功",200);
    }

    /*
     * 开抢
     */
    public function panic(){
        global $G_SHOP;
        $sale_date=$_REQUEST['sale_date'];
        if(!$G_SHOP->currentPCustID){
            $G_SHOP->currentPCustID =$_COOKIE['dunchCookie_pcustID'];
        }
        $custSearchSql="select  is_right  from  dunch_cust_master WHERE pcustID=? ";
        $custSearchQuest=$G_SHOP->DBCA->stmt_query($custSearchSql,'s',$G_SHOP->currentPCustID);
        if($custSearchQuest[0]->is_right==1){
            returnJsonData("一个会员仅限一次",500);
        }


        $panicSql="UPDATE dunch_sale  SET right_num=right_num-1 WHERE sale_date=? and right_num>=1";
        $zt=$G_SHOP->DBCA->stmt_query($panicSql,'s',$sale_date);


        if($zt==0){
            returnJsonData("已抢光",400);
        }else{
            $useSql="UPDATE dunch_sale  SET use_num=use_num+1 WHERE sale_date=? ";
            $G_SHOP->DBCA->stmt_query($useSql,'s',$sale_date);

            $custSql="UPDATE dunch_cust_master  SET is_right=1 WHERE pcustID=? ";
            $G_SHOP->DBCA->stmt_query($custSql,'s',$G_SHOP->currentPCustID);

            //加载短信类
            quanli_include('module/base/common/quanliSms.class.php');
            //实例化短信类
            $quanliSms = new quanliSms();

            /**
             * ============================
             * 发送短信
             * ============================
             */

            $sms_content = $quanliSms->getSmsContent( 'dunch_bespeak_sms','');
            if (!$sms_content) {
                returnJsonData('短信初始化失败', 404);
            }
            if(!$G_SHOP->currentCustomerID){
                $G_SHOP->currentCustomerID =$_COOKIE['dunchCookie_custID'];
            }
            //发送短信
            $result_array = $quanliSms->sendSMS( $G_SHOP->currentCustomerID, $sms_content );

            returnJsonData("预约成功",200);
        }
    }
    /*
     *add by allen.qiang 《allen.qiang@fistforward.com》MK-FUN-AC-004 下午茶项目迭代--下午茶会员权益 start
     */
    public function ckeckRight(){
        global $G_SHOP;
        if(!$G_SHOP->currentPCustID){
            $G_SHOP->currentPCustID =$_COOKIE['dunchCookie_pcustID'];
        }
        $custSql="select is_right from  dunch_cust_master  WHERE pcustID=? ";
        $rightVal=$G_SHOP->DBCA->stmt_query($custSql,'s',$G_SHOP->currentPCustID);
        returnJsonData($rightVal[0]->is_right,200);

    }

    /*
     *add by allen.qiang 《allen.qiang@fistforward.com》MK-FUN-AC-004 下午茶项目迭代--下午茶会员权益 end
     */


    /*
     *add by allen.qiang 《allen.qiang@fistforward.com》MK-FUN-AC-0041 登录或注册下午茶会员 start
     */

    public function quickLogin(){
        global $G_SHOP;
        //检查参数
        if (!isset($_REQUEST['phone']) || empty($_REQUEST['phone'])) {
            returnJsonData('缺少参数');
        }

        $guest = 1; //前台登录会员类型 1、无密码登录的用户 0、会员 2、有密码但没使用

        //实例会员类
        $quanliCust = new quanliCust();

        //查询会员信息
        $arg_array = array(
            'custID' => $_REQUEST['phone']
        );
        $customer_array = $quanliCust->searchCustomerDetail( $arg_array );
        if ($customer_array) {
                $dunch_cust_master=new entity('dunch_cust_master');
                $dunch_cust_master->pcustID=$customer_array['pcustID'];
                $G_SHOP->DBCA->fetch($dunch_cust_master);
                $dunch_cust_master->pcustID=$customer_array['pcustID'];
                $dunch_cust_master->custID=$customer_array['custID'];
                $dunch_cust_master->brandID=1;
                $G_SHOP->DBCA->save($dunch_cust_master);

        } else {

            $pwd = get_random_string(6);

            //前台注册会员信息
            $args_array = array(
                'custID' => $_REQUEST['phone'],
                'pwd' => $pwd,
                'pwd2' => $pwd,
                'custSource' => 1,
                'custType' => 2
            );
            $result_array = $quanliCust->register( $args_array );
            if ($result_array['code'] != 200) {
                returnJsonData($result_array['message'], $result_array['code']);
            }
            //查询会员信息
            $arg_array = array(
                'custID' => $_REQUEST['phone']
            );
            $customer_array = $quanliCust->searchCustomerDetail( $arg_array );
            $dunch_cust_master=new entity('dunch_cust_master');
            $dunch_cust_master->pcustID=$customer_array['pcustID'];
            $G_SHOP->DBCA->fetch($dunch_cust_master);
            $dunch_cust_master->pcustID=$customer_array['pcustID'];
            $dunch_cust_master->custID=$customer_array['custID'];
            $dunch_cust_master->brandID=1;
            $G_SHOP->DBCA->save($dunch_cust_master);
            $customer_array = $result_array['data'];
            /**
             * ============================
             * 发送短信
             * ============================
             */
            //加载短信类
            quanli_include('module/base/common/quanliSms.class.php');

            //实例化短信类
            $quanliSms = new quanliSms();
            //生成短信验证码


            //生成短信内容
            $data_array = array(
                '$pwd' => $pwd
            );
            $sms_content = $quanliSms->getSmsContent( 'dunch_register', $data_array );
            if (!$sms_content) {
                returnJsonData('短信初始化失败', 404);
            }

            //发送短信
            $result_array = $quanliSms->sendSMS( $_REQUEST['phone'], $sms_content );

            /**
             * ============================
             * 发送短信
             * ============================
             */
        }
        $pcustsql='select pcustID from dunch_cust_master  where custID=?';
        $pcustArray=  $G_SHOP->DBCA->stmt_query($pcustsql,'s',$_REQUEST['phone']);
        setcookie('dunchCookie_custID', $_REQUEST['phone'], time()+3600*24*7,'/');//手机号存入cookie
        setcookie('dunchCookie_pcustID', $pcustArray[0]->pcustID, time()+3600*24*7,'/');//会员ID存入cookie
        //更新会员登录信息
        $quanliCust->shopCheckin( $customer_array, $guest);
        returnJsonData('短信验证成功',200);
    }

    /*
     *add by allen.qiang 《allen.qiang@fistforward.com》MK-FUN-AC-0041 登录或注册下午茶会员 end
     */

}
